package com.mlick.dddk.service;


import android.content.Intent;

import com.mlick.dddk.DKApplication;
import com.mlick.dddk.utils.CheckUtil;
import com.mlick.dddk.utils.DKUtils;
import com.mlick.dddk.utils.DateUtils;
import com.mlick.dddk.utils.SysUtils;


/**
 * Created by mlick on 2018-03-22.
 */

public class MyRunable implements Runnable {

    private int flag;

    public MyRunable(int flag) {
        this.flag = flag;
    }

    @Override
    public void run() {

        //SysUtils.out("========================" + SimpleDateFormat.getDateInstance(DateFormat.YEAR_FIELD, new Locale("zh", "CN")).format(System.currentTimeMillis()) + "======================");
        SysUtils.out(flag + "========================" + DateUtils.getDate() + "检测心跳======================");

        try {
            if (flag == -1) {
                boolean isCheck = CheckUtil.isServiceWorked(DKApplication.getInstance().getApplicationContext(), "com.mlick.dddk.service.DKService");
                SysUtils.out("服务是否启动" + isCheck);
                if (!isCheck) {
                    DKApplication.getInstance().startService(new Intent(DKApplication.getInstance(), DKService.class));
                }
            } else {
                DKUtils.rumPro(flag);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
